<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('ggcm:ggcmOrder:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.ggcmOrderId" placeholder="广告传媒订单" clearable></el-input>
          <el-input v-model="search.appUserId" placeholder="会员" clearable></el-input>
          <el-input v-model="search.companyId" placeholder="分公司" clearable></el-input>
          <el-input v-model="search.sysDepartmentId" placeholder="店铺" clearable></el-input>
          <el-input v-model="search.xsSuserId" placeholder="销售员" clearable></el-input>
          <el-input v-model="search.jkSuserId" placeholder="项目总监" clearable></el-input>
          <el-input v-model="search.ggcmMoneyId" placeholder="核销单 现结 不需要核销单" clearable></el-input>
          <el-input v-model="search.productSl" placeholder="订单产品数量 产品项目数" clearable></el-input>
          <el-input v-model="search.orderState" placeholder="0无效 1暂存待确认 2客户已提交   3生效执行中 8已完成  10已完成结束" clearable></el-input>
          <el-input v-model="search.ycState" placeholder=">0 异常订单" clearable></el-input>
          <el-input v-model="search.sumMoney" placeholder="订单总金额" clearable></el-input>
          <el-input v-model="search.sumMoneyZh" placeholder="订单总金额 则后金额" clearable></el-input>
          <el-input v-model="search.sumMoneyCb" placeholder="成本" clearable></el-input>
          <el-input v-model="search.doLevel" placeholder="优先级" clearable></el-input>
          <el-input v-model="search.createId" placeholder="建单人" clearable></el-input>
          <el-input v-model="search.createTime" placeholder="建单时间" clearable></el-input>
          <el-input v-model="search.tjTime" placeholder="提交时间" clearable></el-input>
          <el-input v-model="search.tcTime" placeholder="提成计算时间" clearable></el-input>
          <el-input v-model="search.msg" placeholder="说明" clearable></el-input>
          <el-input v-model="search.hxState" placeholder="" clearable></el-input>
          <el-input v-model="search.hxDate" placeholder="核销日期" clearable></el-input>
          <el-input v-model="search.deleted" placeholder="" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="ggcmOrderId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="广告传媒订单" prop="ggcmOrderId" width="150"></el-table-column>
        <el-table-column label="会员" prop="appUserId" width="150"></el-table-column>
        <el-table-column label="分公司" prop="companyId" width="150"></el-table-column>
        <el-table-column label="店铺" prop="sysDepartmentId" width="150"></el-table-column>
        <el-table-column label="销售员" prop="xsSuserId" width="150"></el-table-column>
        <el-table-column label="项目总监" prop="jkSuserId" width="150"></el-table-column>
        <el-table-column label="核销单 现结 不需要核销单" prop="ggcmMoneyId" width="150"></el-table-column>
        <el-table-column label="订单产品数量 产品项目数" prop="productSl" width="150"></el-table-column>
        <el-table-column label="0无效 1暂存待确认 2客户已提交   3生效执行中 8已完成  10已完成结束" prop="orderState" width="150"></el-table-column>
        <el-table-column label=">0 异常订单" prop="ycState" width="150"></el-table-column>
        <el-table-column label="订单总金额" prop="sumMoney" width="150"></el-table-column>
        <el-table-column label="订单总金额 则后金额" prop="sumMoneyZh" width="150"></el-table-column>
        <el-table-column label="成本" prop="sumMoneyCb" width="150"></el-table-column>
        <el-table-column label="优先级" prop="doLevel" width="150"></el-table-column>
        <el-table-column label="建单人" prop="createId" width="150"></el-table-column>
        <el-table-column label="建单时间" prop="createTime" width="150"></el-table-column>
        <el-table-column label="提交时间" prop="tjTime" width="150"></el-table-column>
        <el-table-column label="提成计算时间" prop="tcTime" width="150"></el-table-column>
        <el-table-column label="说明" prop="msg" width="150"></el-table-column>
        <el-table-column label="" prop="hxState" width="150"></el-table-column>
        <el-table-column label="核销日期" prop="hxDate" width="150"></el-table-column>
        <el-table-column label="" prop="deleted" width="150"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('ggcm:ggcmOrder:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('ggcm:ggcmOrder:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <ggcmOrderEdit-dialog v-if="dialog.ggcmOrderEdit" ref="ggcmOrderEditDialog" @success="handleSaveSuccess" @closed="dialog.ggcmOrderEdit=false"></ggcmOrderEdit-dialog>
</template>

<script>
  import ggcmOrderEditDialog from './ggcmOrderEdit';//1--导入
  export default {
    name: 'ggcmOrder',
    components: {
        ggcmOrderEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          ggcmOrderEdit: false
        },
        apiObj: this.$API.ggcm.ggcmOrder.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        }
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.ggcmOrderEdit = true
        this.$nextTick(() => {
          this.$refs.ggcmOrderEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.ggcmOrderEdit = true
        this.$nextTick(() => {
          this.$refs.ggcmOrderEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await this.$API.ggcm.ggcmOrder.delete.delete(row.ggcmOrderId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
    }
  }
</script>
<style>
</style>
